import { EntitySchema } from '@mikro-orm/core';

export class TypechoContents {
  cid!: number;
  title?: string;
  slug?: string;
  created?: number = 0;
  modified?: number = 0;
  text?: unknown;
  order?: number = 0;
  authorId?: number = 0;
  template?: string;
  type?: string;
  status?: string;
  password?: string;
  commentsNum?: number = 0;
  allowComment?: unknown;
  allowPing?: unknown;
  allowFeed?: unknown;
  parent?: number = 0;
  views?: number = 0;
  likes?: number = 0;
  isrecommend?: number = 0;
  istop?: number = 0;
  isswiper?: number = 0;
}

export const TypechoContentsSchema = new EntitySchema({
  class: TypechoContents,
  properties: {
    cid: { primary: true, type: 'number' },
    title: { type: 'string', length: 150, nullable: true },
    slug: { type: 'string', length: 150, nullable: true, unique: 'slug' },
    created: { type: 'number', nullable: true, default: 0, index: 'created' },
    modified: { type: 'number', nullable: true, default: 0 },
    text: { type: 'unknown', columnType: 'longtext', nullable: true },
    order: { type: 'number', nullable: true, default: 0 },
    authorId: { type: 'number', fieldName: 'authorId', nullable: true, default: 0 },
    template: { type: 'string', length: 32, nullable: true },
    type: { type: 'string', length: 16, nullable: true, default: 'post' },
    status: { type: 'string', length: 16, nullable: true, default: 'publish' },
    password: { type: 'string', length: 32, nullable: true },
    commentsNum: { type: 'number', fieldName: 'commentsNum', nullable: true, default: 0 },
    allowComment: {
      type: 'unknown',
      fieldName: 'allowComment',
      columnType: 'char(1)',
      nullable: true,
      default: '0',
    },
    allowPing: {
      type: 'unknown',
      fieldName: 'allowPing',
      columnType: 'char(1)',
      nullable: true,
      default: '0',
    },
    allowFeed: {
      type: 'unknown',
      fieldName: 'allowFeed',
      columnType: 'char(1)',
      nullable: true,
      default: '0',
    },
    parent: { type: 'number', nullable: true, default: 0 },
    views: { type: 'number', nullable: true, default: 0 },
    likes: { type: 'number', nullable: true, default: 0 },
    isrecommend: { type: 'number', nullable: true, default: 0 },
    istop: { type: 'number', nullable: true, default: 0 },
    isswiper: { type: 'number', nullable: true, default: 0 },
  },
});
